package com.originalpoint.origin_server.service.Impl;

import com.originalpoint.origin_server.mapper.RegisterMapper;
import com.originalpoint.origin_server.pojo.Register;
import com.originalpoint.origin_server.result.RegisterResult;
import com.originalpoint.origin_server.service.RegisterService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

@Service
 class RegisterServiceImpl implements RegisterService {

    @Resource
    private RegisterMapper registerMapper;
    RegisterResult registerResult = new RegisterResult();
    @Override
    public int register(Register register) {
        int result = 0;

        switch (register.getRole()) {
            case 2: // 商家
                result= registerMapper.createMerchat(register);
                break;
            case 3: // 用户
                result= registerMapper.createUser(register);
                break;
        }
        if(result!=0 ){
            registerResult.setSuccess(true);
            registerResult.setMessage("注册成功");
        }else{
            registerResult.setSuccess(false);
            registerResult.setMessage("该账号已被注册");
        }

            return  result;

    }
}
